using System;
using System.Collections.Generic;
using  System.Runtime.InteropServices;

namespace PVTLibrary
{
    [Serializable]
    //modif adel
    //[ComClass(Calculator.ClassId, Calculator.InterfaceId, Calculator.EventsId)]
    public class Calculator
    {
        public const string ClassId  = "5F2B671E-FA61-401e-8D14-71FB5B328F9B";
        public const string InterfaceId  = "0EA44EDE-AD65-435c-B8CC-0D1146BD182B";
        public const string  EventsId  = "0817BD3F-5278-4e49-A7FB-92416A8A7E4E";

        private Dictionary<string, ConstantProperties> availablecomps = null;; 

        /// <summary>
        /// Initializes the calculator and loads the compound databases into memory.
        /// </summary>
        /// <remarks></remarks>
        [DispId(1)] 
        void Initialize()
        {
            //'load databases
            availablecomps = new Dictionary<string, ConstantProperties>();

            //'ChemSep
            LoadCSDB();

            //'load DWSIM XML database
            LoadDWSIMDB();
        }

        /// <summary>
        /// Initializes the calculator and loads the compound databases into memory, including the specified user databases.
        /// </summary>
        /// <param name="userdbs">A string array containing the full path of DWSIM-generated user databases to load.</param>
        /// <remarks></remarks>
        [DispId(2)] 
        void Initialize(string[] userdbs)
        {
            Initialize();

            foreach( var db in userdbs)
                LoadUserDB(db);
        }                    
    
        /// <summary>
        /// Enables CPU parallel processing for some tasks.
        /// </summary>
        /// <remarks></remarks>
        [DispId(3)] 
        void EnableParallelProcessing()
        {
            this.Settings.EnableParallelProcessing = true;
        }

        /// <summary>
        /// Disables CPU parallel processing.
        /// </summary>
        /// <remarks></remarks>
        [DispId(4)] 
        void DisableParallelProcessing()
        { 
            this.Settings.EnableParallelProcessing = false;
        }

        /// <summary>
        /// Enables GPU parallel processing for some tasks. A call to 'InitComputeDevice' is required after this one.
        /// </summary>
        /// <remarks></remarks>
        [DispId(5)] 
        void EnableGPUProcessing()
        {
            this.Settings.EnableGPUProcessing = true;
        }

        /// <summary>
        /// Disables GPU parallel processing.
        /// </summary>
        /// <remarks></remarks>
        [DispId(6)] 
        void DisableGPUProcessing()
        {
            this.Settings.EnableGPUProcessing = true;
        }

        /// <summary>
        /// Initializes the Compute (GPU) device with the default settings (language = OpenCL, first device on the list).
        /// </summary>
        /// <remarks></remarks>
        [DispId(7)] 
        void InitComputeDevice()
        {
            DTL.App.InitComputeDevice();
        }


        /// <summary>
        /// Initializes the Compute (GPU) device.
        /// </summary>
        /// <param name="CudafyTarget">Target language for calculations (CUDA = 0, OpenCL = 1).</param>
        /// <param name="DeviceID">ID of the compute device. Defaults to the first device on the system (DeviceID = 0).</param>
        /// <remarks></remarks>
        [DispId(8)] 
        void InitComputeDevice(int CudafyTarget, int DeviceID  = 0)
        {
            DTL.App.InitComputeDevice(CudafyTarget, DeviceID);
        }

        private void TransferComps(PropertyPackage pp )
        {
            pp.availablecomps = availablecomps;
        }

        private void LoadUserDB(string path)
        {
            /*
            DTL.ClassesBasicasTermodinamica.ConstantProperties cpa;
            cpa = DTL.Databases.UserDB.ReadComps(path);
            For Each cp As DTL.ClassesBasicasTermodinamica.ConstantProperties In cpa
                If Not availablecomps.ContainsKey(cp.Name) Then availablecomps.Add(cp.Name, cp)
            Next
            */
        }

        private void LoadCSDB()
        {
            /*
            Dim csdb As New DTL.Databases.ChemSep
            Dim cpa() As DTL.ClassesBasicasTermodinamica.ConstantProperties
            'Try
            csdb.Load()
            cpa = csdb.Transfer()
            For Each cp As DTL.ClassesBasicasTermodinamica.ConstantProperties In cpa
                If Not availablecomps.ContainsKey(cp.Name) Then availablecomps.Add(cp.Name, cp)
            Next*/
        }

        private void LoadDWSIMDB()
        {
            /*
            Dim dwdb As New DTL.Databases.DWSIM
            Dim cpa() As DTL.ClassesBasicasTermodinamica.ConstantProperties
            dwdb.Load()
            cpa = dwdb.Transfer()
            For Each cp As DTL.ClassesBasicasTermodinamica.ConstantProperties In cpa
                If Not availablecomps.ContainsKey(cp.Name) Then availablecomps.Add(cp.Name, cp)
            Next*/
        }

        public void SetIP(string proppack , PropertyPackage pp , object compounds, object ip1, object ip2, object ip3, object ip4 )
        {
            var pengPack = pp as PengRobinsonPropertyPackage;
            
            if(ip1!=null)
            {
                pengPack.m_pr.InteractionParameters.Clear();
                i = 0;
                foreach( var  c1 in compounds)
                {
                    pengPack.m_pr.InteractionParameters.Add(c1, new Dictionary<string, Auxiliary.PR_IPData))
                    j = 0
                    For Each c2 As String In compounds
                        .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                        With .Item(c1).Item(c2)
                            .kij = ip1(i, j)
                        End With
                        j += 1
                    Next
                    i += 1
                }
            }
            /*
            Dim i, j As Integer

            Select Case proppack
                Case "Peng-Robinson (PR)"
                    With CType(pp, PengRobinsonPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Peng-Robinson-Stryjek-Vera 2 (PRSV2)", "Peng-Robinson-Stryjek-Vera 2 (PRSV2-M)"
                    With CType(pp, PRSV2PropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1.ToLower, New Dictionary(Of String, Auxiliary.PRSV2_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1.ToLower).Add(c2.ToLower, New Auxiliary.PRSV2_IPData())
                                    With .Item(c1.ToLower).Item(c2.ToLower)
                                        .kij = ip1(i, j)
                                        .kji = ip2(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Peng-Robinson-Stryjek-Vera 2 (PRSV2-VL)"
                    With CType(pp, PRSV2VLPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1.ToLower, New Dictionary(Of String, Auxiliary.PRSV2_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1.ToLower).Add(c2.ToLower, New Auxiliary.PRSV2_IPData())
                                    With .Item(c1.ToLower).Item(c2.ToLower)
                                        .kij = ip1(i, j)
                                        .kji = ip2(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Soave-Redlich-Kwong (SRK)"
                    With CType(pp, SRKPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Peng-Robinson / Lee-Kesler (PR/LK)"
                    With CType(pp, PengRobinsonLKPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "UNIFAC"
                    With CType(pp, UNIFACPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "UNIFAC-LL"
                    With CType(pp, UNIFACLLPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "NRTL"
                    With CType(pp, NRTLPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                    With CType(pp, NRTLPropertyPackage).m_uni.InteractionParameters
                        If Not ip2 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.NRTL_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.NRTL_IPData())
                                    With .Item(c1).Item(c2)
                                        .A12 = ip2(i, j)
                                        .A21 = ip3(i, j)
                                        .alpha12 = ip4(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "UNIQUAC"
                    With CType(pp, UNIQUACPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                    With CType(pp, UNIQUACPropertyPackage).m_uni.InteractionParameters
                        If Not ip2 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.UNIQUAC_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.UNIQUAC_IPData())
                                    With .Item(c1).Item(c2)
                                        .A12 = ip2(i, j)
                                        .A21 = ip3(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Modified UNIFAC (Dortmund)"
                    With CType(pp, MODFACPropertyPackage).m_pr.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.PR_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.PR_IPData())
                                    With .Item(c1).Item(c2)
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Lee-Kesler-Plöcker"
                    With CType(pp, LKPPropertyPackage).m_lk.InteractionParameters
                        If Not ip1 Is Nothing Then
                            .Clear()
                            i = 0
                            For Each c1 As String In compounds
                                .Add(c1, New Dictionary(Of String, Auxiliary.LKP_IPData))
                                j = 0
                                For Each c2 As String In compounds
                                    .Item(c1).Add(c2, New Auxiliary.LKP_IPData())
                                    With .Item(c1).Item(c2)
                                        .ID1 = c1
                                        .ID2 = c2
                                        .kij = ip1(i, j)
                                    End With
                                    j += 1
                                Next
                                i += 1
                            Next
                        End If
                    End With
                Case "Chao-Seader"
                Case "Grayson-Streed"
                Case "IAPWS-IF97 Steam Tables"
                Case "Raoult's Law"
            End Select
            */
        }

        /// <summary>
        /// Returns a single constant property value for a compound.
        /// </summary>
        /// <param name="compound">Compound name.</param>
        /// <param name="prop">Property identifier.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(10)] 
        public string GetCompoundConstProp(string compound , string  prop) 
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)
            TransferComps(pp)

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                phase.Componentes.Add(compound, New DTL.ClassesBasicasTermodinamica.Substancia(compound, ""))
                phase.Componentes(compound).ConstantProperties = pp.availablecomps(compound)
            Next

            Dim tmpcomp As ConstantProperties = pp.availablecomps(compound)
            pp._selectedcomps.Add(compound, tmpcomp)
            'pp.availablecomps.Remove(compound)

            ms._pp = pp
            pp.SetMaterial(ms)

            Dim results = null

            results = ms.GetCompoundConstant(New Object() {prop}, New Object() {compound})

            Return results(0)

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing*/
        }

        /// <summary>
        /// Returns a single temperature-dependent property value for a compound.
        /// </summary>
        /// <param name="compound">Compound name.</param>
        /// <param name="prop">Property identifier.</param>
        /// <param name="temperature">Temperature in K.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(11)] public string GetCompoundTDepProp( string compound , string  prop , double temperature )
        {
            /*                
            Dim pp As New RaoultPropertyPackage(True)
            TransferComps(pp)

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                phase.Componentes.Add(compound, New DTL.ClassesBasicasTermodinamica.Substancia(compound, ""))
                phase.Componentes(compound).ConstantProperties = pp.availablecomps(compound)
            Next

            Dim tmpcomp As ConstantProperties = pp.availablecomps(compound)
            pp._selectedcomps.Add(compound, tmpcomp)
            'pp.availablecomps.Remove(compound)

            ms._pp = pp
            pp.SetMaterial(ms)

            Dim results = null

            ms.GetTDependentProperty(New Object() {prop}, temperature, New Object() {compound}, results)

            Return results(0)

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing
            */
        }

        /// <summary>
        /// Returns a single pressure-dependent property value for a compound.
        /// </summary>
        /// <param name="compound">Compound name.</param>
        /// <param name="prop">Property identifier.</param>
        /// <param name="pressure">Pressure in Pa.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(12)] public string GetCompoundPDepProp(string compound, string prop, double pressure )
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)
            TransferComps(pp)

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                phase.Componentes.Add(compound, New DTL.ClassesBasicasTermodinamica.Substancia(compound, ""))
                phase.Componentes(compound).ConstantProperties = pp.availablecomps(compound)
            Next

            Dim tmpcomp As ConstantProperties = pp.availablecomps(compound)
            pp._selectedcomps.Add(compound, tmpcomp)
            'pp.availablecomps.Remove(compound)

            ms._pp = pp
            pp.SetMaterial(ms)

            Dim results = null

            ms.GetPDependentProperty(New Object() {prop}, pressure, New Object() {compound}, results)

            Return results(0)

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing
            */
        }

        /// <summary>
        /// Returns a list of the available single compound constant properties.
        /// </summary>
        /// <returns>A list of the available single compound properties</returns>
        /// <remarks></remarks>
        [DispId(13)] public string[] GetCompoundConstPropList()
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim props As New ArrayList

            props.AddRange(pp.GetConstPropList())

            pp.Dispose()
            pp = Nothing

            Dim values As Object() = props.ToArray

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2
            */
        }

        /// <summary>
        /// Returns a list of the available single compound temperature-dependent properties.
        /// </summary>
        /// <returns>A list of the available single compound properties</returns>
        /// <remarks></remarks>
        [DispId(14)] public string[] GetCompoundTDepPropList() 
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim props As New ArrayList

            props.AddRange(pp.GetTDependentPropList())

            pp.Dispose()
            pp = Nothing

            Dim values As Object() = props.ToArray

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2
            */
        }


        /// <summary>
        /// Returns a list of the available single compound pressure-dependent properties.
        /// </summary>
        /// <returns>A list of the available single compound properties</returns>
        /// <remarks></remarks>
        [DispId(15)]  string[]  GetCompoundPDepPropList() 
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim props As New ArrayList

            props.AddRange(pp.GetPDependentPropList())

            pp.Dispose()
            pp = Nothing

            Dim values As Object() = props.ToArray

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2
            */
        }

        /// <summary>
        /// Calculates properties using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="prop">The property to calculate.</param>
        /// <param name="basis">The returning basis of the properties: Mole, Mass or UNDEFINED.</param>
        /// <param name="phaselabel">The name of the phase to calculate properties from.</param>
        /// <param name="compounds">The list of compounds to include.</param>
        /// <param name="temperature">Temperature in K.</param>
        /// <param name="pressure">Pressure in Pa.</param>
        /// <param name="molefractions">*Normalized* mole fractions of the compounds in the mixture.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(16)] public object[] CalcProp( 
            string proppack, 
            string prop , 
            string basis ,
            string phaselabel , 
            string[] compounds, 
            double temperature, 
            double pressure , 
            double[] molefractions, 
            object ip1  = null, 
            object ip2  = null, 
            object ip3  = null, 
            object ip4 = null) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage = ppm.GetPropertyPackage(proppack)

            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            Dim dwp As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel Then dwp = pi.DWPhaseID
            Next

            ms.SetPhaseComposition(molefractions, dwp)
            ms.Fases(0).SPMProperties.temperature = temperature
            ms.Fases(0).SPMProperties.pressure = pressure

            ms._pp = pp
            pp.SetMaterial(ms)

            If prop.ToLower <> "molecularweight" Then
                pp.CalcSinglePhaseProp(New Object() {prop}, phaselabel)
            End If

            Dim results As Double() = Nothing
            Dim allres As New ArrayList
            Dim i As Integer

            results = Nothing
            If prop.ToLower <> "molecularweight" Then
                ms.GetSinglePhaseProp(prop, phaselabel, basis, results)
            Else
                results = New Double() {pp.AUX_MMM(dwp)}
            End If
            For i = 0 To results.Length - 1
                allres.Add(results(i))
            Next

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing

            Dim values As Object() = allres.ToArray()

            Dim results2(values.Length - 1) As Object

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2
            */
        }

        /// <summary>
        /// Calculates properties using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The Property Package instance to use.</param>
        /// <param name="prop">The property to calculate.</param>
        /// <param name="basis">The returning basis of the properties: Mole, Mass or UNDEFINED.</param>
        /// <param name="phaselabel">The name of the phase to calculate properties from.</param>
        /// <param name="compounds">The list of compounds to include.</param>
        /// <param name="temperature">Temperature in K.</param>
        /// <param name="pressure">Pressure in Pa.</param>
        /// <param name="molefractions">*Normalized* mole fractions of the compounds in the mixture.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(17)] public object[] CalcProp( 
             PropertyPackage proppack, 
             string prop , 
             string basis , 
             string phaselabel, 
             string[] compounds, 
             double temperature, 
             double pressure, 
             double[] molefractions, 
             object  ip1  = null, 
             object  ip2 = null, 
             object  ip3 = null, 
                object  ip4 = null) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            Dim dwp As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel Then dwp = pi.DWPhaseID
            Next

            ms.SetPhaseComposition(molefractions, dwp)
            ms.Fases(0).SPMProperties.temperature = temperature
            ms.Fases(0).SPMProperties.pressure = pressure

            ms._pp = pp
            pp.SetMaterial(ms)

            If prop.ToLower <> "molecularweight" Then
                pp.CalcSinglePhaseProp(New Object() {prop}, phaselabel)
            End If

            Dim results As Double() = Nothing
            Dim allres As New ArrayList
            Dim i As Integer

            results = Nothing
            If prop.ToLower <> "molecularweight" Then
                ms.GetSinglePhaseProp(prop, phaselabel, basis, results)
            Else
                results = New Double() {pp.AUX_MMM(dwp)}
            End If
            For i = 0 To results.Length - 1
                allres.Add(results(i))
            Next

            ms.Dispose()
            ms = Nothing

            Dim values As Object() = allres.ToArray()

            Dim results2(values.Length - 1) As Object

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2*/
        }

        /// <summary>
        /// Calculates two phase properties (K-values, Ln(K-values) or Surface Tension) using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="prop">The property to calculate.</param>
        /// <param name="basis">The returning basis of the properties: Mole, Mass or UNDEFINED.</param>
        /// <param name="phaselabel1">The name of the first phase.</param>
        /// <param name="phaselabel2">The name of the second phase.</param>
        /// <param name="compounds">The list of compounds to include.</param>
        /// <param name="temperature">Temperature in K.</param>
        /// <param name="pressure">Pressure in Pa.</param>
        /// <param name="molefractions1">*Normalized* mole fractions of the compounds in the first phase.</param>
        /// <param name="molefractions2">*Normalized* mole fractions of the compounds in the second phase.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(18)] 
        public object[] CalcTwoPhaseProp( 
             string proppack , 
             string prop, 
             string basis, 
             string phaselabel1, 
             string phaselabel2, 
             string[] compounds , 
             double temperature, 
             double pressure, 
             double[] molefractions1 , 
             double[]  molefractions2 , 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage = ppm.GetPropertyPackage(proppack)

            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            Dim dwp1 As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel1 Then dwp1 = pi.DWPhaseID
            Next

            Dim dwp2 As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel2 Then dwp2 = pi.DWPhaseID
            Next

            ms.SetPhaseComposition(molefractions1, dwp1)
            ms.SetPhaseComposition(molefractions2, dwp2)
            ms.Fases(0).SPMProperties.temperature = temperature
            ms.Fases(0).SPMProperties.pressure = pressure

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.CalcTwoPhaseProp(New Object() {prop}, New Object() {phaselabel1, phaselabel2})

            Dim results As Double() = Nothing
            Dim allres As New ArrayList
            Dim i As Integer

            results = Nothing
            ms.GetTwoPhaseProp(prop, New Object() {phaselabel1, phaselabel2}, basis, results)
            For i = 0 To results.Length - 1
                allres.Add(results(i))
            Next

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing

            Dim values As Object() = allres.ToArray()

            Dim results2(values.Length - 1) As Object

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2*/
        }

        /// <summary>
        /// Calculates two phase properties (K-values, Ln(K-values) or Surface Tension) using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The Property Package instance to use.</param>
        /// <param name="prop">The property to calculate.</param>
        /// <param name="basis">The returning basis of the properties: Mole, Mass or UNDEFINED.</param>
        /// <param name="phaselabel1">The name of the first phase.</param>
        /// <param name="phaselabel2">The name of the second phase.</param>
        /// <param name="compounds">The list of compounds to include.</param>
        /// <param name="temperature">Temperature in K.</param>
        /// <param name="pressure">Pressure in Pa.</param>
        /// <param name="molefractions1">*Normalized* mole fractions of the compounds in the first phase.</param>
        /// <param name="molefractions2">*Normalized* mole fractions of the compounds in the second phase.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(19)] public object[] CalcTwoPhaseProp( 
             PropertyPackage proppack , 
             string prop, 
             string basis, 
             string phaselabel1, 
             string phaselabel2, 
             string[] compounds , 
             double temperature , 
             double pressure , 
             double[] molefractions1 , 
             double[]  molefractions2, 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage
            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            Dim dwp1 As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel1 Then dwp1 = pi.DWPhaseID
            Next

            Dim dwp2 As PropertyPackages.Fase = PropertyPackages.Fase.Mixture
            For Each pi As PropertyPackages.PhaseInfo In pp.PhaseMappings.Values
                If pi.PhaseLabel = phaselabel2 Then dwp2 = pi.DWPhaseID
            Next

            ms.SetPhaseComposition(molefractions1, dwp1)
            ms.SetPhaseComposition(molefractions2, dwp2)
            ms.Fases(0).SPMProperties.temperature = temperature
            ms.Fases(0).SPMProperties.pressure = pressure

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.CalcTwoPhaseProp(New Object() {prop}, New Object() {phaselabel1, phaselabel2})

            Dim results As Double() = Nothing
            Dim allres As New ArrayList
            Dim i As Integer

            results = Nothing
            ms.GetTwoPhaseProp(prop, New Object() {phaselabel1, phaselabel2}, basis, results)
            For i = 0 To results.Length - 1
                allres.Add(results(i))
            Next

            pp.Dispose()
            pp = Nothing

            ms.Dispose()
            ms = Nothing

            Dim values As Object() = allres.ToArray()

            Dim results2(values.Length - 1) As Object

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2
            */
        }

        /// <summary>
        /// Returns a list of the available Property Packages.
        /// </summary>
        /// <returns>A list of the available Property Packages</returns>
        /// <remarks></remarks>
        [DispId(20)] 
        public string[] GetPropPackList() 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim values As Object() = ppm.GetPropertyPackageList()

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2

            ppm.Dispose()
            ppm = Nothing
            */
        }

        /// <summary>
        /// Returns a Property Package instance that can be reused on multiple function calls.
        /// </summary>
        /// <returns>A Property Package instance.</returns>
        /// <remarks></remarks>
        [DispId(21)] public PropertyPackage GetPropPackInstance(string proppackname) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage = ppm.GetPropertyPackage(proppackname)

            TransferComps(pp)

            ppm.Dispose()
            ppm = Nothing

            Return pp
            */
        }


        /// <summary>
        /// Returns a list of the available single-phase properties.
        /// </summary>
        /// <returns>A list of the available single-phase properties</returns>
        /// <remarks></remarks>
        [DispId(22)] public string[] GetPropList()
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim values As Object() = pp.GetSinglePhasePropList()

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2

            pp.Dispose()
            pp = Nothing
            */
        }


        /// <summary>
        /// Returns a list of the available two-phase properties.
        /// </summary>
        /// <returns>A list of the available two-phase properties</returns>
        /// <remarks></remarks>
        [DispId(23)] public string[] GetTwoPhasePropList() 
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim values As Object() = pp.GetTwoPhasePropList()

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2

            pp.Dispose()
            pp = Nothing
            */
        }

        /// <summary>
        /// Returns a list of the available phases.
        /// </summary>
        /// <returns>A list of the available phases</returns>
        /// <remarks></remarks>
        [DispId(24)] 
        public string[] GetPhaseList() 
        {
            /*
            Dim pp As New RaoultPropertyPackage(True)

            Dim values As Object() = pp.GetPhaseList()

            Dim results2(values.Length - 1) As String
            Dim i As Integer

            For i = 0 To values.Length - 1
                results2(i) = values(i)
            Next

            Return results2

            pp.Dispose()
            pp = Nothing
            */
        }

        /// <summary>
        /// Returns a list of the available compounds.
        /// </summary>
        /// <returns>A list of the available compounds</returns>
        /// <remarks></remarks>
        [DispId(25)] 
        public string[] GetCompoundList() 
        {
            /*
            Try

                Dim comps As New ArrayList

                For Each c As ConstantProperties In availablecomps.Values
                    comps.Add(c.Name)
                Next

                Dim values As Object() = comps.ToArray

                Dim results2(values.Length - 1) As String
                Dim i As Integer

                For i = 0 To values.Length - 1
                    results2(i) = values(i)
                Next

                Return results2

            Catch ex As Exception

                Return New Object() {ex.ToString}

            End Try
            */
        }

        /// <summary>
        /// Calculates a PT Flash using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="T">Temperature in K.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(26)] 
        public object[,] PTFlash( 
             string proppack , 
             int flashalg , 
             double P , 
             double T , 
             string[] compounds , 
             double[] molefractions , 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = ppm.GetPropertyPackage(proppack)
            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.temperature = T
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            Select Case flashalg
                Case 1
                    pp.FlashAlgorithm = PropertyPackages.FlashMethod.DWSIMDefault
                Case 2
                    pp.FlashAlgorithm = PropertyPackages.FlashMethod.InsideOut
                Case 3
                    pp.FlashAlgorithm = PropertyPackages.FlashMethod.InsideOut3P
                Case 6
                    pp.FlashAlgorithm = PropertyPackages.FlashMethod.NestedLoops3P
            End Select

            pp._ioquick = False
            pp._tpseverity = 2
            Dim comps(compounds.Length - 1) As String
            Dim k As Integer
            For Each c As String In compounds
                comps(k) = c
                k += 1
            Next
            pp._tpcompids = comps

            pp.CalcEquilibrium(ms, "TP", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CAPEOPEN110.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 1, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            If TypeOf proppack Is String Then
                pp.Dispose()
                pp = Nothing
            End If

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }


        /// <summary>
        /// Calculates a PH Flash using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="H">Mixture Mass Enthalpy in kJ/kg.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(27)] public 
        object[,] PHFlash(string proppack , 
             int flashalg , 
             double P , 
             double H , 
             string[] compounds , 
             double[] molefractions , 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null,
            double   InitialTemperatureEstimate = 0.0)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = ppm.GetPropertyPackage(proppack)
            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.enthalpy = H
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            pp._ioquick = False
            pp._tpseverity = 2
            Dim comps(compounds.Length - 1) As String
            Dim k As Integer
            For Each c As String In compounds
                comps(k) = c
                k += 1
            Next
            pp._tpcompids = comps

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PH", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            If TypeOf proppack Is String Then
                pp.Dispose()
                pp = Nothing
            End If

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Calculates a PH Flash using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="S">Mixture Mass Entropy in kJ/[kg.K].</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(28)] public object[,] PSFlash( 
             string proppack , 
             int flashalg , 
             double P , 
             double S, 
             string[] compounds , 
             double[] molefractions , 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null,
            double  InitialTemperatureEstimate  = 0.0) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = ppm.GetPropertyPackage(proppack)
            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.entropy = S
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            pp._ioquick = False
            pp._tpseverity = 2
            Dim comps(compounds.Length - 1) As String
            Dim k As Integer
            For Each c As String In compounds
                comps(k) = c
                k += 1
            Next
            pp._tpcompids = comps

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PS", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            If TypeOf proppack Is String Then
                pp.Dispose()
                pp = Nothing
            End If

            ms.Dispose()
            ms = Nothing

            Return fractions
        */
        }

        /// <summary>
        /// Calculates a PVF Flash using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="VF">Mixture Mole Vapor Fraction.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(29)] public object[,] PVFFlash( 
             string proppack , 
             int flashalg , 
             double P , 
             double VF , 
             object[] compounds , 
             double[] molefractions , 
            object ip1 = null, 
            object ip2 = null, 
            object ip3 = null, 
            object ip4 = null,
            double   InitialTemperatureEstimate  = 0.0) 
        {
            /*

            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = ppm.GetPropertyPackage(proppack)
            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(2).SPMProperties.molarfraction = VF
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            pp._ioquick = False
            pp._tpseverity = 2
            Dim comps(compounds.Length - 1) As String
            Dim k As Integer
            For Each c As String In compounds
                comps(k) = c
                k += 1
            Next
            pp._tpcompids = comps

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PVF", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            If TypeOf proppack Is String Then
                pp.Dispose()
                pp = Nothing
            End If

            ms.Dispose()
            ms = Nothing

            Return fractions
                */
        }

        /// <summary>
        /// Calculates a TVF Flash using the selected Property Package.
        /// </summary>
        /// <param name="proppack">The name of the Property Package to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="T">Temperature in K.</param>
        /// <param name="VF">Mixture Mole Vapor Fraction.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        ///<param name="InitialPressureEstimate">Initial estimate for the pressure, in Pa.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(30)] public object[,]  TVFFlash( 
             string proppack , 
             int flashalg , 
             double T , 
             double VF, 
             string[] compounds , 
             double[] molefractions , 
             object ip1 = null, 
             object ip2 = null, 
             object ip3 = null, 
             object ip4 = null,
             double InitialPressureEstimate  = 0.0) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = ppm.GetPropertyPackage(proppack)
            TransferComps(pp)

            SetIP(proppack, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(2).SPMProperties.molarfraction = VF
            ms.Fases(0).SPMProperties.temperature = T

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            pp._ioquick = False
            pp._tpseverity = 2
            Dim comps(compounds.Length - 1) As String
            Dim k As Integer
            For Each c As String In compounds
                comps(k) = c
                k += 1
            Next
            pp._tpcompids = comps

            ms.Fases(0).SPMProperties.pressure = InitialPressureEstimate

            pp.CalcEquilibrium(ms, "TVF", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.pressure.GetValueOrDefault

            If TypeOf proppack Is String Then
                pp.Dispose()
                pp = Nothing
            End If

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Calculates a PT Flash using the referenced Property Package.
        /// </summary>
        /// <param name="proppack">A reference to the Property Package object to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="T">Temperature in K.</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(31)] 
        public object[,] PTFlash( 
             PropertyPackage proppack , 
             int flashalg , 
             double P ,
             double T ,
             string[] compounds ,
             double[] molefractions ,
            object ip1 = null,
            object ip2 = null,
            object ip3 = null,
            object ip4 = null)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.temperature = T
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            pp.CalcEquilibrium(ms, "TP", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 1, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Calculates a PH Flash using the referenced Property Package.
        /// </summary>
        /// <param name="proppack">A reference to the Property Package object to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="H">Mixture Mass Enthalpy in kJ/kg.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(32)] public object[,] PHFlash( 
             PropertyPackage proppack ,
             int flashalg ,
             double P ,
            double H ,
             string[] compounds ,
             double[] molefractions ,
            object ip1 = null,
            object ip2 = null,
            object ip3 = null,
            object ip4 = null,
            double InitialTemperatureEstimate  = 0.0) 
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.enthalpy = H
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PH", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            ms.Dispose()
            ms = Nothing

            Return fractions
            */ 
        }

        /// <summary>
        /// Calculates a PS Flash using the referenced Property Package.
        /// </summary>
        /// <param name="proppack">A reference to the Property Package object to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="S">Mixture Mass Entropyin kJ/[kg.K].</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(33)] public object[,] PSFlash( 
             PropertyPackage proppack ,
             int flashalg ,
             double P ,
             double S ,
             string[] compounds ,
             double[] molefractions ,
            object ip1 = null,
            object ip2 = null,
            object ip3 = null,
            object ip4 = null,
            double InitialTemperatureEstimate  = 0.0)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(0).SPMProperties.entropy = S
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PS", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Calculates a PVF Flash using the referenced Property Package.
        /// </summary>
        /// <param name="proppack">A reference to the Property Package object to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="P">Pressure in Pa.</param>
        /// <param name="VF">Mixture Mole Vapor Fraction.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        /// <param name="InitialTemperatureEstimate">Initial estimate for the temperature, in K.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(34)]
        public object[,] PVFFlash(
            PropertyPackage proppack,
            int flashalg,
            double P,
            double VF,
            string[] compounds,
            double[] molefractions,
            object ip1 = null,
            object ip2 = null,
            object ip3 = null,
            object ip4 = null,
            double InitialTemperatureEstimate = 0.0)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(2).SPMProperties.molarfraction = VF
            ms.Fases(0).SPMProperties.pressure = P

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            ms.Fases(0).SPMProperties.temperature = InitialTemperatureEstimate

            pp.CalcEquilibrium(ms, "PVF", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.temperature.GetValueOrDefault

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Calculates a TVF Flash using the referenced Property Package.
        /// </summary>
        /// <param name="proppack">A reference to the Property Package object to use.</param>
        /// <param name="flashalg">Flash Algorithm (0 or 2 = Nested Loops VLE, 1 = Inside-Out VLE, 3 = Inside-Out VLLE, 4 = Gibbs VLE, 5 = Gibbs VLLE, 6 = Nested-Loops VLLE (Hybrid), 7 = Nested-Loops SLE, 8 = Nested-Loops Immisc., 9 = Simple LLE, 10 = Nested-Loops SLE (Solid Solution), 11 = Nested Loops VLLE)</param>
        /// <param name="T">Temperature in K.</param>
        /// <param name="VF">Mixture Mole Vapor Fraction.</param>
        /// <param name="compounds">Compound names.</param>
        /// <param name="molefractions">Compound mole fractions.</param>
        /// <param name="ip1">Interaction Parameters Set #1.</param>
        /// <param name="ip2">Interaction Parameters Set #2.</param>
        /// <param name="ip3">Interaction Parameters Set #3.</param>
        /// <param name="ip4">Interaction Parameters Set #4.</param>
        ///<param name="InitialPressureEstimate">Initial estimate for the pressure, in Pa.</param>
        /// <returns>A matrix containing phase fractions and compound distribution in mole fractions.</returns>
        /// <remarks></remarks>
        [DispId(35)] public object[,] TVFFlash( 
             PropertyPackage proppack ,
             int flashalg ,
             double T ,
             double VF ,
             string[] compounds ,
             double[] molefractions ,
            object ip1 = null,
            object ip2 = null,
            object ip3 = null,
            object ip4 = null,
            double  InitialPressureEstimate  = 0.0)
        {
            /*
            Dim ppm As New CAPEOPENPropertyPackageManager()

            Dim pp As PropertyPackages.PropertyPackage

            pp = proppack
            TransferComps(pp)

            SetIP(pp.ComponentName, pp, compounds, ip1, ip2, ip3, ip4)

            ppm.Dispose()
            ppm = Nothing

            Dim ms As New Streams.MaterialStream("", "")

            For Each phase As DTL.ClassesBasicasTermodinamica.Fase In ms.Fases.Values
                For Each c As String In compounds
                    phase.Componentes.Add(c, New DTL.ClassesBasicasTermodinamica.Substancia(c, ""))
                    phase.Componentes(c).ConstantProperties = pp.availablecomps(c)
                Next
            Next

            For Each c As String In compounds
                Dim tmpcomp As ConstantProperties = pp.availablecomps(c)
                If Not pp._selectedcomps.ContainsKey(c) Then pp._selectedcomps.Add(c, tmpcomp)
                'pp.availablecomps.Remove(c)
            Next

            ms.SetOverallComposition(molefractions)
            ms.Fases(2).SPMProperties.molarfraction = VF
            ms.Fases(0).SPMProperties.temperature = T

            ms._pp = pp
            pp.SetMaterial(ms)

            pp.FlashAlgorithm = flashalg

            ms.Fases(0).SPMProperties.pressure = InitialPressureEstimate

            pp.CalcEquilibrium(ms, "TVF", "UNDEFINED")

            Dim labels As String() = Nothing
            Dim statuses As CapeOpen.eCapePhaseStatus() = Nothing

            ms.GetPresentPhases(labels, statuses)

            Dim fractions(compounds.Length + 2, labels.Length - 1) As Object

            Dim res = null

            Dim i, j As Integer
            i = 0
            For Each l As String In labels
                If statuses(i) = CapeOpen.eCapePhaseStatus.CAPE_ATEQUILIBRIUM Then
                    fractions(0, i) = labels(i)
                    ms.GetSinglePhaseProp("phasefraction", labels(i), "Mole", res)
                    fractions(1, i) = res(0)
                    ms.GetSinglePhaseProp("fraction", labels(i), "Mole", res)
                    For j = 0 To compounds.Length - 1
                        fractions(2 + j, i) = res(j)
                    Next
                End If
                i += 1
            Next

            fractions(compounds.Length + 2, 0) = ms.Fases(0).SPMProperties.pressure.GetValueOrDefault

            ms.Dispose()
            ms = Nothing

            Return fractions
            */
        }

        /// <summary>
        /// Returns a list of the thermodynamic models.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(36)] 
        public ArrayList GetModelList() 
        {
            /*
            Dim modellist As New ArrayList

            modellist.Add("Peng-Robinson")
            modellist.Add("Peng-Robinson-Stryjek-Vera 2 (Van Laar)")
            modellist.Add("Peng-Robinson-Stryjek-Vera 2 (Margules)")
            modellist.Add("Soave-Redlich-Kwong")
            modellist.Add("Lee-Kesler-Plöcker")
            modellist.Add("PC-SAFT")
            modellist.Add("NRTL")
            modellist.Add("UNIQUAC")

            Return modellist
            */
        }

        /// <summary>
        /// "Returns the interaction parameters stored in DWSIM's database for a given binary/model combination.
        /// </summary>
        /// <param name="Model">Thermodynamic Model (use 'GetModelList' to get a list of available models).</param>
        /// <param name="Compound1">The name of the first compound.</param>
        /// <param name="Compound2">The name of the second compound.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        [DispId(37)] 
        public InteractionParameter GetInteractionParameterSet( string Model,  string Compound1,  string Compound2 ) 
        {
            /*
            Dim pars As New Dictionary(Of String, Object)

            Select Case Model
                Case "Peng-Robinson"
                    Dim pp As New PengRobinsonPropertyPackage(True)
                    If pp.m_pr.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_pr.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound1)(Compound2).kij}}
                        Else
                            If pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "Peng-Robinson-Stryjek-Vera 2 (Van Laar)"
                    Dim pp As New PRSV2VLPropertyPackage(True)
                    If pp.m_pr.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_pr.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound1)(Compound2).kij},
                                                                           {"kji", pp.m_pr.InteractionParameters(Compound1)(Compound2).kji}}
                        Else
                            If pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij},
                                                                                   {"kji", pp.m_pr.InteractionParameters(Compound2)(Compound1).kji}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kji},
                                                                           {"kji", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "Peng-Robinson-Stryjek-Vera 2 (Margules)"
                    Dim pp As New PRSV2PropertyPackage(True)
                    If pp.m_pr.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_pr.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound1)(Compound2).kij},
                                                                           {"kji", pp.m_pr.InteractionParameters(Compound1)(Compound2).kji}}
                        Else
                            If pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij},
                                                                                   {"kji", pp.m_pr.InteractionParameters(Compound2)(Compound1).kji}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kji},
                                                                           {"kji", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "Soave-Redlich-Kwong"
                    Dim pp As New SRKPropertyPackage(True)
                    If pp.m_pr.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_pr.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound1)(Compound2).kij}}
                        Else
                            If pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "Lee-Kesler-Plöcker"
                    Dim pp As New LKPPropertyPackage(True)
                    If pp.m_pr.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_pr.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound1)(Compound2).kij}}
                        Else
                            If pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_pr.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_pr.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"kij", pp.m_pr.InteractionParameters(Compound2)(Compound1).kij}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "NRTL"
                    Dim pp As New NRTLPropertyPackage(True)
                    If pp.m_uni.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_uni.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound1)(Compound2).A12},
                                                                           {"A21", pp.m_uni.InteractionParameters(Compound1)(Compound2).A21},
                                                                           {"alpha", pp.m_uni.InteractionParameters(Compound1)(Compound2).alpha12}}
                        Else
                            If pp.m_uni.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_uni.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound2)(Compound1).A12},
                                                                                   {"A21", pp.m_uni.InteractionParameters(Compound2)(Compound1).A21},
                                                                                   {"alpha", pp.m_uni.InteractionParameters(Compound2)(Compound1).alpha12}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_uni.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_uni.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound2)(Compound1).A21},
                                                        {"A21", pp.m_uni.InteractionParameters(Compound2)(Compound1).A12},
                                                        {"alpha", pp.m_uni.InteractionParameters(Compound2)(Compound1).alpha12}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
                Case "UNIQUAC"
                    Dim pp As New UNIQUACPropertyPackage(True)
                    If pp.m_uni.InteractionParameters.ContainsKey(Compound1) Then
                        If pp.m_uni.InteractionParameters(Compound1).ContainsKey(Compound2) Then
                            pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound1)(Compound2).A12},
                                                                           {"A21", pp.m_uni.InteractionParameters(Compound1)(Compound2).A21}}
                        Else
                            If pp.m_uni.InteractionParameters.ContainsKey(Compound2) Then
                                If pp.m_uni.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                                    pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound2)(Compound1).A12},
                                                                                   {"A21", pp.m_uni.InteractionParameters(Compound2)(Compound1).A21}}
                                End If
                            End If
                        End If
                    ElseIf pp.m_uni.InteractionParameters.ContainsKey(Compound2) Then
                        If pp.m_uni.InteractionParameters(Compound2).ContainsKey(Compound1) Then
                            pars = New Dictionary(Of String, Object) From {{"A12", pp.m_uni.InteractionParameters(Compound2)(Compound1).A21},
                                                                          {"A21", pp.m_uni.InteractionParameters(Compound2)(Compound1).A12}}
                        End If
                    End If
                    pp.Dispose()
                    pp = Nothing
            End Select

            Return New InteractionParameter() With {.Comp1 = Compound1, .Comp2 = Compound2, .Model = Model, .Parameters = pars}
            */
        }
    }
}
